﻿using System.Collections.ObjectModel;
using GalaSoft.MvvmLight;
using MvvmCodeReduction.Model;

namespace MvvmCodeReduction.ViewModel
{
    public class CustomersViewModel : ViewModelBase
    {
        private IRepository _repository;

        public const string CustomersPropertyName = "Customers";
        private ObservableCollection<CustomerViewModel> _customers;
        public ObservableCollection<CustomerViewModel> Customers
        {
            get
            {
                return _customers;
            }

            set
            {
                if (_customers == value)
                {
                    return;
                }
                _customers = value;
                RaisePropertyChanged(CustomersPropertyName);
            }
        }

        public CustomersViewModel(IRepository repository)
        {
            _repository = repository;
            Customers = new ObservableCollection<CustomerViewModel>();
            foreach (Model.Customer customer in _repository.GetCustomers())
            {
                Customers.Add(new CustomerViewModel(customer));
            }
        } 
    }
}
